//
//  MenuViewController.m
//  PCNews
//
//  Created by PengchengWang on 16/3/1.
//  Copyright © 2016年 pengchengWang. All rights reserved.
//

#import "MenuViewController.h"
#import "MenuTableViewCell.h"
#import "NewsViewController.h"
#import "DrawerViewController.h"
#import "EvaluateViewController.h"
#import "AppDelegate.h"
#import "ImageViewController.h"
#import "CommentViewController.h"
#import "SendValue.h"
@interface MenuViewController ()<UITableViewDataSource,UITableViewDelegate>

//@property (weak, nonatomic) IBOutlet UITableView *tableVC;
@property(nonatomic,strong)UITableView *tableVC;

@end

@implementation MenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setViews];
    // Do any additional setup after loading the view.
    [self.tableVC registerNib:[UINib nibWithNibName:@"MenuTableViewCell" bundle:nil] forCellReuseIdentifier:@"MenuTableViewCell"];
}

-(void)setViews{
    UIView * topView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 64)];
    UIImageView * im =[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 40, 40)];
    im.image=[UIImage imageNamed:@"left_logo"];
    UILabel * textLable =[[UILabel alloc]initWithFrame:CGRectMake(70, 20, 250, 40)];
    textLable.text =@"驱家新闻";
    textLable.font=[UIFont fontWithName:@"Helvetica" size:20];
    textLable.textColor =[UIColor whiteColor];
    topView.backgroundColor=kColor(48, 48, 48, 1);
    [topView addSubview:im];
    [topView addSubview:textLable];
    [self.view addSubview:topView];
    self.tableVC = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, 200, kScreenHeight-64) style:(UITableViewStylePlain)];
    [self.view addSubview:self.tableVC];
    self.tableVC.backgroundColor = kColor(60, 60, 60, 1);
    self.tableVC.delegate = self;
    self.tableVC.dataSource = self;
#pragma mark - UITableView 行线隐藏 separatorStyle
    self.tableVC.separatorStyle = NO;
    [self.mbPreHUD hide:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuTableViewCell" forIndexPath:indexPath];
    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
    cell.selectedBackgroundView.backgroundColor =kColor(79, 79, 79, 1);
    cell.backgroundColor =kColor(60, 60, 60, 1);
    cell.textLabel.textColor=[UIColor whiteColor];
    switch (indexPath.row) {
        case 0:
            cell.headCell.text = @"新闻";
            cell.imgV.image = [UIImage imageNamed:@"menu_left_news"];
            break;
        case 1:
            cell.headCell.text = @"评测";
            cell.imgV.image = [UIImage imageNamed:@"menu_left_review"];
            break;
        case 2:
            cell.headCell.text = @"图片";
            cell.imgV.image = [UIImage imageNamed:@"menu_left_atlas"];
            break;
        case 3:
            cell.headCell.text = @"评论";
            cell.imgV.image = [UIImage imageNamed:@"menu_left_comm"];
            break;
        default:
            break;
    }
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    AppDelegate *app = [UIApplication sharedApplication].delegate;
    DrawerViewController *drawer = app.draw;
    switch (indexPath.row) {
        case 0:{
            NewsViewController *newsVC = [NewsViewController new];
            UINavigationController *news_naVC = [[UINavigationController alloc]initWithRootViewController:newsVC];
            [news_naVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar_bg_7"] forBarMetrics:UIBarMetricsDefault];
                        [self sengMsg:[NewsViewController class]];
            [drawer setRootViewController:news_naVC];
            break;
        }
        case 1:{
            EvaluateViewController *evaluateVC = [EvaluateViewController new];
            UINavigationController *evaluate_naVC = [[UINavigationController alloc]initWithRootViewController:evaluateVC];
            [evaluate_naVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar_bg_7"] forBarMetrics:UIBarMetricsDefault];
                        [self sengMsg:[EvaluateViewController class]];
            [drawer setRootViewController:evaluate_naVC];
            break;
        }
        case 2:{
            ImageViewController *imageVC = [ImageViewController new];
            UINavigationController *image_naVC = [[UINavigationController alloc]initWithRootViewController:imageVC];
            [image_naVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar_bg_7"] forBarMetrics:UIBarMetricsDefault];
                        [self sengMsg:[ImageViewController class]];
            [drawer setRootViewController:image_naVC];

            break;
        }
        case 3:{
            CommentViewController *commentVC = [CommentViewController new];
            UINavigationController *comment_naVC = [[UINavigationController alloc]initWithRootViewController:commentVC];
            [comment_naVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar_bg_7"] forBarMetrics:UIBarMetricsDefault];
                        [self sengMsg:[CommentViewController class]];
            [drawer setRootViewController:comment_naVC];

            break;
        }
        default:
            break;
    }
}

- (void)sengMsg:(Class)sender {
    [SendValue shareInstance].myclass = sender;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
